import processing.core.*;
import processing.xml.*;

import fisica.*;

import java.applet.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
import java.util.zip.*;
import java.util.regex.*;

public class Bubbles extends PApplet {

	/**
	 * Buttons and bodies
	 * 
	 * by Ricard Marxer
	 * 
	 * This example shows how to create a blob.
	 */

	FWorld world;

	int circleCount = 20;
	float hole = 50;
	float topMargin = 50;
	float bottomMargin = 300;
	float sideMargin = 100;
	float xPos = 0;

	public void setup() {
		size(400, 400);
		smooth();

		Fisica.init(this);

		world = new FWorld();
		world.setGravity(0, -50);
		world.setEdges();

	}

	public void draw() {
		background(80, 120, 200);

		if ((frameCount % 40) == 1) {
			FCircle b = new FCircle(40);
			float s = random(30, 40);
			float space = (width - sideMargin * 2 - s);
			xPos = (xPos + random(s, space / 2)) % space;
			// b.setAsCircle(sideMargin + xPos+s/2, height-random(100), s, 20);
			b.setStroke(0);
			b.setPosition(xPos, space);
			b.setStrokeWeight(2);
			b.setFill(255);
			b.setStatic(false);
			b.setDensity(1);
			world.add(b);
		}

		world.step();
		world.draw();
	}

	public void keyPressed() {
		try {
			saveFrame("screenshot.png");
		} catch (Exception e) {
		}
	}
	
	public void mousePressed() {
		FBody fBody = world.getBody(mouseX, mouseY);
		if(fBody instanceof FCircle){
			FCircle circle = (FCircle)fBody;
			circle.setSize(circle.getSize()+2);
		}
		println("mousePressed");
	}
	
	static public void main(String args[]) {
		PApplet.main(new String[] { "--bgcolor=#DFDFDF", "Bubbles" });
	}
}
